package com.wc.acwing.思维.领导者;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2025/3/14 10:57
 * @description
 * https://www.acwing.com/problem/content/description/4891/
 */
public class Main {
    /**
     * 思路：
     * 分类讨论:
     * 两个领导着都满足第一条, 那就说明每一个领导者都是第一个
     * 两个领导者, 一个满足第一条 b, 一个满足第二条 a
     * 那么首先说明 b 一定不在第一个位置, 就找从 b 往前的找 a 是否 e[a] >= b的位置
     *
     * 两个领导都满足第二条, 不存在, 因为领导者只能包含后面的牛, 不能包含前面的
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 100010;
    static char[] s = new char[N];
    static int[] p = new int[N], e = new int[N];
    static int n;

    public static void main(String[] args) {
        n = sc.nextInt();
        s = (" " + sc.next()).toCharArray();
        for (int i = 1; i <= n; i++) {
            if (s[i] == 'G') p[i] = 1;
        }
        for (int i = 1; i <= n; i++) e[i] = sc.nextInt();
        int[] l = {n, n}, r = {1, 1};
        for (int i = 1; i <= n; i++) {
            int t = p[i];
            l[t] = Math.min(l[t], i);
            r[t] = Math.max(r[t], i);
        }
        int res = 0;
        // 都满足第一条
        if (e[l[0]] >= r[0] && e[l[1]] >= r[1]) res++;
        int a = p[1], b = a ^ 1;

        // 后面的牛满足第二个条件
        if (e[l[b]] >= r[b]) {
            for (int i = 1; i < l[b]; i++) {
                if (e[i] >= l[b]) res++;
            }
            // 有可能和第一个重复了
            if (e[l[a]] >= l[b] && e[l[a]] >= r[a]) res--;
        }
        out.println(res);
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}

